package com.team.Room;


import java.util.Vector;

public class DDZCards
{
   
  Vector cards = new Vector() ;
  
//  private int  CurrentLength;//size
  int   nLen;//????CurrentLength丄1�7样的〄1�7

  int   nType;//每次根据vector，得到它的ntype，�1�7�度如何?
  int   nLevel;//根据不同的type，得到不同type下的nlevel〄1�7
  //ddz数据结构可以不用。因为它的很多方法，属�1�7�，在一个vector里搞定�1�7�1�7

  void SortDetail(){
    
  }
//  void swap( int , int ){
//    
//  }
//  
//  int GetTupleInfo( char tupleInfo[16] ){
//    
//  }
//
//  BOOL Contain(DDZCards& clDDZCards){
//    
//  }  
  
  public int getLen(){
    return cards.size() ;
 }
  

  void ReleaseAll(){
//    CurrentLength = 0 ;
    cards.removeAllElements() ;//add 090807
    nLen = 0 ;
    nType = 0 ;
    nLevel = 0 ;
  }
  
  /**根据索引，得到牌的编号�1�7�1�7------------------*/
  public int getNumberByIndex(int index){
      if(index >= 0 && index < cards.size())
      {
         return ((LordCard)cards.elementAt(index)).number ;
      }
      else 
      {
         return 0 ;
      }
  }
  
  /**根据索引，得到牌的value牌面倄1�7---------*/
  public int getValueByIndex(int index){
      if(index >= 0 && index < cards.size())
      {
         return ((LordCard)cards.elementAt(index)).value ;
      }
      else 
      {
         return 0 ;
      }
  }
  //根据索引，得到lordCard对象
  public LordCard getLordCardByIndex(int index){
    if(index >= 0 && index < cards.size())
    {
       return ((LordCard)cards.elementAt(index)) ;
    }
    else 
    {
       return null ;
    }
  }
  
  
  /**获取牌集合中牌的种类:777 8 99返回3-----*/
  int GetTupleInfo( byte[] tupleInfo)//16
  {
//    MEMSET( tupleInfo , 0 , 16 );
    
//    byte[] temp = new byte[16];
    
    int i;

    for( i = 0 ; i < tupleInfo.length ; i ++ )
    {
      tupleInfo[i] = 0;
    }
    
    for( i = 0 ; i < getLen() ; i ++ )
    {
//      tupleInfo[cards[i].number] ++;
      tupleInfo[getValueByIndex(i)] ++;
    }

    int nCountNoneZero = 0;

    for( i = 0 ; i < 16 ; i ++ )
    {
      if( tupleInfo[i] > 0)
      {
        nCountNoneZero ++;
      }
    }

    return nCountNoneZero;  }
  
  
  
  /**对换集合中i和j位置的牌----------------*/
  void swap( int i , int j )//?
  {
      if (i < 0 && j < 0 && i >= getLen() && j >= getLen())
      {
      return;
      }

//    LordCard tempCard = new LordCard(getLordCardByIndex(i).number) ;//cards[i];
    LordCard tempCard = getLordCardByIndex(i) ;//cards[i];
//      getLordCardByIndex(i) 
    
    /////#mdebug info
    ///System.out.println("getLordCardByIndex(i).number="+getLordCardByIndex(i).number);
    ///System.out.println("getLordCardByIndex(j).number="+getLordCardByIndex(j).number);
    /////#enddebug
    
//    cards[i] = cards[j];
//    cards[j] = tempCard;
     
    cards.setElementAt((LordCard)cards.elementAt(j), i) ;//索引i的地方，设置索引j的元素�1�7�1�7
    cards.setElementAt(tempCard,j); //索引j的地方，设置索引i的元素�1�7�1�7
    
    /////#mdebug info
    ///System.out.println("swap getLordCardByIndex(i).number="+getLordCardByIndex(i).number);
    ///System.out.println("swap getLordCardByIndex(j).number="+getLordCardByIndex(j).number);
    /////#enddebug
     
    
  }
  
  public DDZCards copy(DDZCards src){
        DDZCards temp = new DDZCards() ;
        Object[] objects = new Object[src.cards.size()] ;
        src.cards.copyInto(objects) ;
        for(int k = 0 ; k < objects.length ; k ++ ){
           temp.cards.addElement((LordCard) (objects[k])) ; 
        }
        temp.nLen = src.nLen ; 
        temp.nType = src.nType ; 
        temp.nLevel =  src.nLevel ; 
        return temp ;
  }
  
  void AddCard(LordCard card)
  {//add     
    cards.addElement(card);
  }
  
  
  /**
  void AddCard( LordCard card )
  {
//    AddCard( card.shape , card.number , card.bSelected );//color倄1�7 ,value值牌面�1�7�1�7 
    
    AddCard(card.number , card.color ,card.value ,card.selected) ;//牌编叄1�7,颜色，牌面�1�7�1�7,是否选择
  }
  */
  
  void AddCard(int color , int value , boolean bSel)
  {
    
    AddCard(getNumberFromColorValue(color,value) , color ,value ,bSel) ; //根据color,value 得到number值�1�7�1�7
  }
  
  /** 根据牌的编号 确定牌面倄1�7 */
  byte getNumberFromColorValue(int color,int value)
  {
//    value = cardNO==54?15:(cardNO==53?14:(cardNO % 13));
//    if(value == 0) value = 13;
//    /** 根据牌的编号 确定牌颜艄1�7 */
//    color = (int) (cardNO - 1) / 13 + 1;
      
      byte number = 0 ;
      if(value > 13){
         if(value == 14){
            number = 53 ;
         }else if(value == 15){
            number = 54 ;
         }
      }else {
        number = (byte) ( ((color -1) * 13) + value) ;
      }
      return number ;

  }
  
//  /**牌编叄1�7 按黑桃A_K、红桃A-K、梅花A-K、方块A-K顺序丄1�752；小玄1�7大王54共计54张牌*/
//  public byte number;
//  /**牌色: 1＄1�7�1�7�1�7�示黑桃、红桃�1�7�梅花�1�7�方坄1�7*/
//  public int color;  
//  /**牌面倄1�7 1~15*/
//  public int value;  
  
  
  void AddCard(byte number , int color , int value , boolean bSel)
  {
    //ASSERT( CurrentLength <= MAX_CARDS_NUMBER );
    /**
    if (getCurrentLength() > MAX_CARDS_NUMBER)
    {
      return;
    }
    */
    
//    if( ( 0 < color && color < 5  && 0 < value && value < 14 ) || 
//        ( 5 == color && ( 14 == value || 15 == value ) ) ||  //0 == color
//        ( 0 == color && 0 == value ) //???
//        )
    {
//      cards[CurrentLength].shape  = shape;
//      cards[CurrentLength].number = number;
//      cards[CurrentLength].bSelected = bSel;
      
      LordCard card = new LordCard(number) ;
      /**
      card.color = color ; 
      card.value = value ; 
      */
      card.selected = bSel ; 
      
      
      
      cards.addElement(card) ;
      
//      CurrentLength ++;
    }
    
//    //#debug info
//    System.out.println("AddCard.number="+number+",color="+color+",value="+value+",bSel="+bSel);
  }
  
  /**将obCards中的牌加入当前集各1�7----------------*/
  void AddCards(DDZCards obCards )
  {
    for( int i = 0 ; i < obCards.getLen() ; i ++ )
    {
       AddCard( obCards.getLordCardByIndex(i)) ;//obCards.cards[i] );
    }
  }
  
  
  boolean Contain(DDZCards clDDZCards){
       return Contain(clDDZCards,false) ;
  }
  
  /**判断clDDZCards是否包含于当前集合中：bEqual是否要求两个组合完全相同----------------*/
  boolean Contain(DDZCards clDDZCards,boolean bEqual)
  {
    
    boolean bContain = false ;
    int[] nContain = new int[20] ;
    for (int i=0;i<20;i++)
    {
      nContain[i] = 0;
    }

    if ((!bEqual && clDDZCards.getLen() <= getLen()) || (bEqual && clDDZCards.getLen() == getLen()))
    {
      for (int i=0; i<clDDZCards.getLen(); i++)
      {
        bContain = false ;
        for (int j=0; j<getLen(); j++)
        {
          if(nContain[j] ==0 && clDDZCards.getValueByIndex(i) == getValueByIndex(j))//牌面倄1�7 
          {
            nContain[j] = 1;
            bContain = true;
            break;
          }
        }
        if (!bContain)
        {
          return false;
        }
      }
    }
    return bContain;
    
//    boolean bContain = false ;
//    int[] nContain = new int[20];
//    for (int i=0;i<20;i++)
//    {
//      nContain[i] = 0;
//    }
//
//    if (clDDZCards.getCurrentLength() <= getCurrentLength())
//    {
//      for (int i=0; i<clDDZCards.getCurrentLength(); i++)
//      {
//        bContain = false;
//        for (int j=0; j<getCurrentLength(); j++)
//        {
////          if(nContain[j] ==0 && clDDZCards.cards[i].number == cards[j].number)
//            if(nContain[j] ==0 && clDDZCards.getValueByIndex(i) == getValueByIndex(j))//牌面倄1�7 
//          {
//            nContain[j] = 1;
//            bContain = true;
//            break;
//          }
//        }
//        if (!bContain)
//        {
//          return false;
//        }
//      }
//    }
//    return bContain;
  }
  
  
  
  

}
